#!/bin/sh
#
# This is the script for generating files for a specific Dalton test job.
#
# For the .check file ksh or bash is preferred, otherwise use sh
# (and hope it is not the old Bourne shell, which will not work)
#
if [ -x /bin/ksh ]; then
   CHECK_SHELL='#!/bin/ksh'
elif [ -x /bin/bash ]; then
   CHECK_SHELL='#!/bin/bash'
else
   CHECK_SHELL='#!/bin/sh'
fi


#######################################################################
#  TEST DESCRIPTION
#######################################################################
cat > cc_rsp_gamma.info <<'%EOF%'
   cc_rsp_gamma
   ------------
   Molecule:         HF in C2
   Wave Function:    CCS / 6-31G**
   Test Purpose:     Second hyperpolarizabilities (cubic response):
                     - Parallel isotropic average (gamma_|| ) 
                     - A & B coefficients  (2. and 4. order disp.
                       coefficients)
                     - Explicitly use symmetry of linear molecules
%EOF%

#######################################################################
#  INTEGRAL INPUT
#######################################################################
cat > cc_rsp_gamma.mol <<'%EOF%'
BASIS
6-31G**
Hydrogen flourid
small test basis
    2    1  Y  X      1.00D-15
        9.0   1    
F     0.0000000000000000  0.0000000000000000 1.76320000000000000      
        1.0   1
H     0.0000000000000000  0.0000000000000000 0.00000000000000000      
%EOF%

#######################################################################
#  DALTON INPUT
#######################################################################
cat > cc_rsp_gamma.dal <<'%EOF%'
**DALTON INPUT
.RUN WAVE FUNCTIONS
**INTEGRAL
.DIPLEN
**WAVE FUNCTIONS
.TITLE
  second hyperpolarizability for the HF molecule
  for a CCS wavefunction compute:
  - parallel isotropic average (gamma_|| ) 
  - A & B coefficients  (2. and 4. order disp. coefficients)
  - use explicitly symmetry of linear molecules
.CC
*SCF INPUT 
.THRESH
 1.0d-12
*CC INPUT 
.CCS
.THRENR
 1.0d-8
.THRLEQ
 1.0d-8
*CCCR
.AVERAGE
GAMMA_PAR            
LINEAR
.DISPCF
  4
**END OF DALTON INPUT
%EOF%
#######################################################################

 

#######################################################################

#######################################################################
#  CHECK SCRIPT
#######################################################################
echo $CHECK_SHELL >cc_rsp_gamma.check
cat >>cc_rsp_gamma.check <<'%EOF%'
log=$1

if [ `uname` = Linux ]; then
   GREP="egrep -a"
else
   GREP="egrep"
fi

if $GREP -q "not implemented for parallel calculations" $log; then
   echo "TEST ENDED AS EXPECTED"
   exit 0
fi

# SCF energy:
CRIT1=`$GREP "Final * HF energy:" $log | $GREP "\-100.008919(8|9)." | wc -l`
CRIT2=`$GREP "Total SCF   energy:                  \-100.008919(8|9)." $log | wc -l`
TEST[1]=`expr $CRIT1 \+ $CRIT2` 
CTRL[1]=2
ERROR[1]="ENERGIES NOT CORRECT"

# CCS gamma dispersion coefficients
# ZDIPLEN    ZDIPLEN    ZDIPLEN    ZDIPLEN        0    133.41562       133.41562       133.41562       133.41562
#                                                 2    6168.2521       3084.1260       2056.0840       1028.0420
#                                                 4    185371.80       48397.312       24249.067       5377.4791      
# gamma_{||}                                      0    31.367109       31.367109       31.367109       31.367109
#                                                 2    1637.6833       818.84164       545.89443       272.94721
#                                                 4    59709.456       15538.195       7720.3056       1726.4661     
# gamma_0   31.367109
# A         4.3508506
# B         13.760163         B        -6.4912034               
CRIT1=`$GREP "0    133\.4156.       133\.4156.       133\.4156.       133\.4156." $log | wc -l`
CRIT2=`$GREP "2    6168\.25(2|3).       3084\.126.       2056\.084.       1028\.042." $log | wc -l`
CRIT3=`$GREP "4    185371\.8.       48397\.3(1|2).       24249\.0(6|7).       5377\.4(79|80)." $log | wc -l`
CRIT4=`$GREP "0    31\.3671(0|1).       31\.3671(0|1).       31\.3671(0|1).       31\.3671(0|1)." $log | wc -l`
CRIT5=`$GREP "2    1637\.683.       818\.841(6|7|8).       545\.894(4|5).       272\.9472." $log | wc -l`
CRIT6=`$GREP "4    59709\.4..       15538\.(19|20).       7720\.30..       1726\.466." $log | wc -l`
CRIT7=`$GREP "gamma_0   31\.3671.." $log | wc -l`
CRIT8=`$GREP "A         4\.35085.." $log | wc -l`
CRIT9=`$GREP "B         13\.7601..         B.       \-6\.49120.." $log | wc -l`
TEST[2]=`expr $CRIT1 \+ $CRIT2 \+ $CRIT3 + $CRIT4 \+ $CRIT5 \+ $CRIT6 + $CRIT7 \+ $CRIT8 \+ $CRIT9` 
CTRL[2]=9
ERROR[2]="CCS GAMMA DISPERSION COEFFICIENTS NOT CORRECT"


PASSED=1
for i in 1 2
do
   if [ ${TEST[i]} -ne ${CTRL[i]} ]; then
     echo "${ERROR[i]} ( test = ${TEST[i]}; control = ${CTRL[i]} ); "
     PASSED=0
   fi
done

if [ $PASSED -eq 1 ]
then
  echo TEST ENDED PROPERLY
  exit 0
else
  echo THERE IS A PROBLEM
  exit 1
fi                
%EOF%
#######################################################################
